﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace BuyTicket.Models
{
    class QueryArgs
    {
        public QueryArgs()
        {
            this.Persons = new List<Person>();
        }

        public bool IsStudent { get; set; }

        public Station StartStation { get; set; }

        public Station EndStation { get; set; }

        public DateTime Date { get; set; }

        public List<Person> Persons { get; set; }

        public bool Verify()
        {
            if(this.StartStation==null
                || this.EndStation==null)
            {
                MessageBox.Show("订票信息不全!");
                return false;
            }
            if (StartStation.QueryName == EndStation.QueryName)
            {
                MessageBox.Show("站点信息错误,不能选择相同的始发站与终点站!");
                return false;
            }
            if (Date.Subtract(DateTime.Now).Days < 2)
            {
                MessageBox.Show("乘车日期错误，只能订购剩余天数大于2天的车票!");
                return false;
            }
            if (Persons.Count == 0)
            {
                MessageBox.Show("还没有任何订票用户!");
                return false;
            }
            return true;
        }

        public override string ToString()
        {
            return string.Format("method=queryLeftTicket&orderRequest.train_date={0}&orderRequest.from_station_telecode={1}&orderRequest.to_station_telecode={2}&orderRequest.train_no=&trainPassType=QB&trainClass=QB%23D%23Z%23T%23K%23QT%23&includeStudent={3}&seatTypeAndNum=&orderRequest.start_time_str=00%3A00--24%3A00",
                Date.ToString("yyyy-MM-dd"),
                StartStation.QueryName,
                EndStation.QueryName,
                IsStudent?"0X00":"00");
        }
    }
}
